<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改商品信息</title>
</head>
<style>
    .main{
        width:50%;
        height:400px;
        border: 2px solid orange;
        margin:60px auto;
        line-height:50px;
        padding-left: 30px;
    }
</style>
<body>
   <div class=main>
       <h2>修改选中商品信息</h2>
       <form action="#" method="POST" enctype="multipart/form-data">
            商品名称：<input type=text name=productname size=20 required placeholder="请输入新的商品名称" /><br/>
            商品类型：<select name=producttype >
                 <option>零食类</option>
                 <option>饮料类</option>
                 <option>文具类</option>
                 <option>日用品类</option>
                 <option>菜类</option>
                 <option>酒类</option>
                 <option>奶类</option>
                  </select>
            &nbsp;&nbsp;商品价格：<input type=text name=productprice size=20 required placeholder="请输入新的商品价格" /><br/>
            商品数量：<input type=text name=productcount  size=20 required placeholder="请输入新的商品数量" />
            &nbsp;&nbsp;入库日期：<input type=date name=date size=20 required /><br/>
           &nbsp;&nbsp; 商品图片：<input type="file" name=picture required /><br/>
            <input type="submit" name="submit" value=修改>
            &nbsp;&nbsp;<a href="subper.php">返回</a>
        </form>   
   </div> 
</body>
</html>

<?php

header("content-type:text/html; charset=utf-8");
if(isset($_POST['submit'])){
$productname=$_POST['productname'];
$producttype=$_POST['producttype'];
$productprice=$_POST['productprice'];
$productcount=$_POST['productcount'];
$inputdate=$_POST['date'];


$sppicture=$_FILES['picture'];
$sppictureName=$sppicture['name'];
$sppictureTemp=$sppicture['tmp_name'];
$destination="uploads/".$sppictureName;
move_uploaded_file($sppictureTemp,$destination);
$picturesrc="uploads/".$sppictureName;

$id=$_GET['iid'];
$serverLink=@mysql_connect("localhost","root","root") or die("连接服务器失败！程序中断");
mysql_query("set names 'utf-8'");
$dbLink= @mysql_select_db("supermarket") or die("打开supermarket数据库失败！程序中断");
$updatesql="update product set productname='$productname',producttype='$producttype',productprice='$productprice',productcount='$productcount',inputdate='$inputdate',picturesrc='$picturesrc' where Id=$id";
$update=mysql_query($updatesql);
$fhxx1=mysql_affected_rows();
if($fhxx1>0){
    echo "修改成功";
    header("refresh:2;url=subper.php");
}else{
    echo "修改失败";
    header("refresh:2;url=update.php");
}
mysql_close($serverLink);
}
?>